package cn.com.exlibris.util;



import java.io.*;
import java.util.*;
import java.text.*;

public class Test {
	public static void main(String[] args) throws IOException {
		 java.util.Date current=new java.util.Date();
     //java.text.SimpleDateFormat sdf=new java.text.SimpleDateFormat("yyyy-MMM-dd hh:mm:ss:SSS");
     java.text.SimpleDateFormat sdf=new java.text.SimpleDateFormat("yyyyMMddHHmmssSSS"); 
     String c=sdf.format(current);
     System.out.println(c);
     
     Date now = new Date();

     DateFormat df = DateFormat.getDateInstance();

     String s = df.format(now);

     System.out.println("Today is " + s);
     
     Date   d=new   Date();   
     SimpleDateFormat   sdf1=new   SimpleDateFormat("dd/MMM/yyyy",Locale.US);   
     System.out.println(sdf1.format(d)); 
     
     try {   
       SimpleDateFormat sd3 = new SimpleDateFormat("yyyyMMdd");   
       Date date2 = sd3.parse("20090425");   
       System.out.println(date2); 
       
       SimpleDateFormat   sdf2=new   SimpleDateFormat("dd/MMM/yyyy",Locale.US);   
       System.out.println(sdf2.format(date2)); 
   } catch (ParseException e) {   
       // TODO Auto-generated catch block   
       e.printStackTrace();   
   }   

   





/*
	getDate("20090331",-365);
	
	System.out.println(getDate("20080331","yyyyMMdd",-365));
	
	String tmp_middle="100  L$$a20031226e20031998ekmy0chiy50^^^^^^ea";
	
	String field_100="";
	field_100=tmp_middle.substring(0, 9)+"^^^^^^^^"+tmp_middle.substring(17, 18);
	field_100+="^^^^^^^^"+tmp_middle.substring(26);
	//field_100="0045"+field_100;
	
	System.out.println("tmp_middle:  "+tmp_middle);
	System.out.println("field_100 :  "+field_100);
	
	
//String 	search_field = "7[0-9][0-9][\\s0-9][\\s0-9]L$$";

String 	search_field = "70110L$$";


String aaa="12345670110L$$dfdf ";

System.out.println("search_field :  "+aaa.indexOf(search_field));


String pattern1 = "7[0-9][0-9][\\s0-9][\\s0-9]L$$";    //该正则表达式表示包含任意多个英文字母或者空格
System.out.println("用正则表达式匹配成功？" + aaa.matches(pattern1));

*/



	}
	
	private static void info(String msg) {
		//System.out.print("Fatal Error:");
		System.out.println(msg);
		System.exit(1);
	}
	/**
   * 得到给定日期N天后的日期
   * @param num
   * @return
   */
  public static void getDate(String datestr,int num) {
      String pattern = "yyyyMMdd";
      SimpleDateFormat format = new SimpleDateFormat(pattern);
      try{
          Date date1 = format.parse(datestr);
          long time = date1.getTime()+(1000L * 60 * 60 * 24 * num);            
          Date date = new Date();
          if (time > 0) {
              date.setTime(time);
          }
          System.out.println(format.format(date));
      }catch(Exception e){}
  }
  
  
  /**
   * 得到给定日期N天后的日期
   * @param num
   * @return
   */
  public static String getDate(String datestr,String pattern,int num) {
      //String pattern = "yyyy-MM-dd";
  	String returnStr="";
      SimpleDateFormat format = new SimpleDateFormat(pattern);
      try{
          Date date1 = format.parse(datestr);
          long time = date1.getTime()+(1000L * 60 * 60 * 24 * num);            
          Date date = new Date();
          if (time > 0) {
              date.setTime(time);
          }
          //System.out.println(format.format(date));
          returnStr=format.format(date);
      }catch(Exception e){}
      return returnStr;
  }


	
}

